const query = require('../models');


module.exports = {
  //获取数据
  get:  (req, res)=> {
    console.log('接收到用户请求：', req.query);
    let category = req.query.category;
    console.log(category)

    const sql = req.query.sql;
    console.log(sql)
    query(sql, null)
      .then((doc) => {
        console.log('请求成功' )
        if (doc.length === 0) {
          res.json({
            code: '1001',
            msg: '数据库为空'
          });
        } else {
          console.log('返回数据，',doc)
          res.json({
            code: '200',
            msg: '查询成功',
            data: doc,
          });

        }
      })
      .catch( (err)=> {
        console.log('查询请求失败，错误', err);
      }
      )
  },

}